import { onLoad } from "@dcloudio/uni-app";
import { getCurrentInstance, nextTick, onMounted, onUpdated, ref } from "vue";
const res = uni.getSystemInfoSync();
const windowHeight = res.windowHeight - 85;

export default function useScrollView() {
  const intoView = ref(0);
  const preHeight = ref(0);
  var instance = getCurrentInstance();

  const scrollTop = async () => {
    await nextTick();
    var query = uni.createSelectorQuery().in(instance);
    query.select("#content").fields({ size: true }, (eles: any) => {
      intoView.value = eles.height - preHeight.value;
      preHeight.value = eles.height;
    });
    query.exec();
  };

  const scrollBottom = async () => {
    await nextTick();
    var query = uni.createSelectorQuery().in(instance);
    query.select("#content").fields({ size: true }, (eles: any) => {
      intoView.value = eles.height - windowHeight;
      preHeight.value = eles.height;
    });
    query.exec();
  };
  return {
    intoView,
    scrollTop,
    scrollBottom
  };
}
